package com.bardsoftware.foronuvolo.server;

import java.util.ArrayList;

import javax.jdo.annotations.Persistent;

import com.bardsoftware.foronuvolo.client.AddFeedService;
import com.bardsoftware.foronuvolo.data.FeedForListening;
import com.google.common.collect.HashMultimap;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class AddFeedServiceImpl extends RemoteServiceServlet implements AddFeedService {		
	
	@SuppressWarnings("serial")
	public String addFeed(String feedUrl, String userId) {
		FeedForListening feed = FeedForListening.find(feedUrl);
		if(feed != null) {			
			feed.addSubscriber(userId);
			feed.save();			
		}
		else {			
			ArrayList<String> users = new ArrayList<String>();
			users.add(userId);
			FeedForListening newFeed = new FeedForListening(feedUrl,users);
			newFeed.save();			
		}
		return "OK";
	}	
}
